package com.muyu.system.danmo.mq;

import cn.hutool.json.JSONUtil;
import com.muyu.system.danmo.dto.PaymentCallBackResult;
import com.muyu.system.danmo.service.PayService;
import com.muyu.system.danmo.vo.RefundResultServiceVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import static com.muyu.common.core.constant.TopicConstant.COMMON_TOPIC_NORMAL;
import static com.muyu.system.danmo.util.ConsumerGroupConstant.PAY_NOTIFY_GROUP;
import static com.muyu.system.danmo.util.ConsumerGroupConstant.REFUND_PAY_NOTIFY_GROUP;
import static com.muyu.system.danmo.util.TagConstant.PAY_NOTIFY_TAG;
import static com.muyu.system.danmo.util.TagConstant.REFUND_PAY_NOTIFY_TAG;


/**
 * 三方退款回调，之后发送mq
 * @author Administrator
 */
@RocketMQMessageListener(
        topic = COMMON_TOPIC_NORMAL,
        consumerGroup = REFUND_PAY_NOTIFY_GROUP ,
        selectorExpression = REFUND_PAY_NOTIFY_TAG
)
@Component
@RequiredArgsConstructor
@Slf4j
public class RefundPayCallbackMessageConsumer implements RocketMQListener<String> {

    private final PayService payService;
    @Override
    public void onMessage(String message) {
        log.info("退款回调mq消息：{}", message);
        payService.completeRefundOrder(JSONUtil.toBean(message, RefundResultServiceVO.class));
    }
}
